package Operation;
import Exception.PassWorldException;
import Account.*;

import java.util.HashMap;
import java.util.Scanner;

public abstract class IOperation {


    public abstract void work(Account account,AcountList acountList);

    public  IOperation doOperation(int i){
        IOperation[] iOperations = new IOperation[]{
                null,
                new DepositOperation(),
                new WithdrawMoneyOperation(),
                new QueryOperation(),
                new ChangePasswordOperation(),
                new AddAccountOperation()
        };
        return iOperations[i];
    }
    public  Account login (HashMap<String,Account> map)throws PassWorldException {
        Scanner scanner = new Scanner(System.in);
        Account a = null;
        while(a==null){
            System.out.println("请输入账号");
            String id = scanner.next();
            a = map.get(id);
            if(a==null){
                System.out.print("找不到账号>");
                System.out.println("退出输入》-999");
                System.out.println("继续登录输入》69");
                int num = scanner.nextInt();
                if(num==-999){
                    return null;
                }
            }
        }
        //输入正确账号，验证账号。
        for(int i = 0;i<3;i++){
            System.out.println("输入密码》");
            String PassWorld = scanner.next();
            if(PassWorld.equals(a.getPassWord())){
                System.out.println("输入正确");
                System.out.println(a.toString());
                return a;
            }
            System.out.print("密码错误》");
        }
        //输入账号错误
        System.out.print("输入密码错误三次，请重新登录");
        return null;

    }
    public int menu() {
        System.out.println("请选择要选择的的操作》");
        System.out.println("1.存款");
        System.out.println("2.取款");
        System.out.println("3.查询余额");
        System.out.println("4.修改个人密码");
        System.out.println("5.开通账户");
        System.out.println("0.退出");
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        return input;
    }
}
